package com.gudogudo.battleworm.contact {
	import Box2D.Dynamics.b2ContactFilter;
	import Box2D.Collision.Shapes.b2Shape;
	import Box2D.Collision.Shapes.b2FilterData;	

	/**
	 * @author zhangs
	 */
	public class ContactFilter extends b2ContactFilter {
		public function ContactFilter() {
		}

		public override function ShouldCollide(shape1 : b2Shape, shape2 : b2Shape) : Boolean {
			var filter1:b2FilterData = shape1.GetFilterData();
			var filter2:b2FilterData = shape2.GetFilterData();
			
			if (filter1.groupIndex == filter2.groupIndex && filter1.groupIndex != 0)
			{
				return filter1.groupIndex > 0;
			}
			
			if ((filter1.groupIndex == ContactConfig.groupIndex_Bullet && filter2.groupIndex == ContactConfig.groupIndex_Bound) || 
				(filter2.groupIndex == ContactConfig.groupIndex_Bullet && filter1.groupIndex == ContactConfig.groupIndex_Bound)) {
				return false;
			}
			
			if ((filter1.groupIndex == ContactConfig.groupIndex_Bullet && filter2.groupIndex == ContactConfig.groupIndex_Player) || 
				(filter2.groupIndex == ContactConfig.groupIndex_Bullet && filter1.groupIndex == ContactConfig.groupIndex_Player)) {
				return false;
			}
			
			var collide:Boolean = (filter1.maskBits & filter2.categoryBits) != 0 && (filter1.categoryBits & filter2.maskBits) != 0;
			return collide;
		}
	}
}
